<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    cancelText="关闭"
    okText="确认推送"
    @ok="sendProfessorChooseToDing"
    @cancel="handleCancel"
  >
  <a-card :bordered="false">
      <a-table
        bordered
        rowKey="dingUserId"
        :columns="innerColumns"
        :dataSource="dataSource01"
        :pagination="false">

        <span slot="professorInProjectStates" slot-scope="text,record">
            <label :class="record.professorInProjectStates==='同意' ? 'fontgreen' : (record.professorInProjectStates==='待审核' ? 'fontyellow':(record.professorInProjectStates==='管理员删除')?'fontdelete':'fontred')">{{record.professorInProjectStates}}</label>
          </span>

        <span slot="action" slot-scope="text,record">
            <JInputPop
              :disabled="!(record.professorInProjectStates==='等待管理员确认'||record.professorInProjectStates==='待审核')"
              title="删除原因"
              isbutton="true"
              :record="record"
              @change="deleteOneProfessor"
            />
          </span>
      </a-table>

    <projectProfessorInfo-modal ref="modalForm" @ok="modalFormOk"></projectProfessorInfo-modal>
  </a-card>
  </j-modal>
</template>
<style>
  .fontgreen{
    color:green;
  }
  .fontyellow{
    color:gold;
  }
  .fontred{
    color:red;
  }
  .fontdelete{
    color: #aaa0a0;
  }
</style>

<script>

import {deleteAction, getAction, downFile, getFileAccessHttpUrl, postAction} from '@api/manage'
  import '@assets/less/TableExpand.less'
  import { loadCategoryData } from '@api/api'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProjectProfessorInfoModal from './ProjectProfessorInfoModal'
  import JInputPop from '@comp/jeecg/minipop/JInputPop'
  export default {
    name: "ProjectProfessorInfoList",
    components: {
      ProjectProfessorInfoModal,
      JInputPop,
    },
    data () {
      return {
        reRecord:{},
        dataSource01:{},
        dataSource02:{},
        title:"操作",
        width:800,
        visible: false,
        description: '项目所需专家抽取状态管理页面',
        professorList:[],
        childRows:"",
        // 表头
         innerColumns:[
          { title: '专家姓名', dataIndex: 'professorName' },
          { title: '专家在项目中的职位', dataIndex:'professorInProjectProfessorType' },
          { title: '是否同意',
            scopedSlots: { customRender: 'professorInProjectStates' }
          },
           {
             title: '操作',
             dataIndex: 'action',
             align:"center",
             width:100,
             scopedSlots: { customRender: 'action' }
           }
        ],
        url: {
          list:"/org/projectOwnProfessor/list",
          delete:"/deleteOneProfessor",
          sendToDing:"/sendProfessorChooseToDing"
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    created() {
    },
    methods: {
      add(record){
        this.reRecord=record
        let selecturl=this.url.list+"/"+record.id;
        getAction(selecturl, "").then((res) => {
          if (res.success) {
            let dataSource0 = res.result.records;
            this.dataSource01=dataSource0[0].project.professorList;
            this.dataSource02=dataSource0[0].project;
            this.childRows=dataSource0[0].id;
          }
          else{
            this.$message.warning(res.message)
          }
        })
        this.visible=true;
      },
      handleCancel(){
        this.visible=false;
      },
      sendProfessorChooseToDing(){
        var that = this;
        let sendUrl = that.url.sendToDing+"/"+this.childRows;
        console.log(this.dataSource02.projectStatus)
        if(this.dataSource02.projectStatus==="待确认"){
          that.loading=true;
          getAction(sendUrl,"").then((res)=>{
            that.$message.success(res.message)
          }).finally(()=>{
            that.loading=false;
          })
        }else{
          that.$message.error("已经向专家推送过了!")
        }
        this.visible=false;
      },
      handleExpand(expanded,record) {
        if (expanded === true) {
          this.professorList = record.project.professorList;
          this.childRows=[];
          this.childRows.push(record.id);
        }else{
          this.childRows=[];
        }
      },
      deleteOneProfessor:function (deleteCause,record) {
        var that = this;
        that.loading = true;
        console.log("record.dingUserId---------------->"+record.dingUserId)
        var deleteUrl=this.url.delete+"/"+this.childRows+"/"+record.dingUserId+"/"+deleteCause;
        console.log("deleteCause1231231232")
        console.log(deleteCause)
        if(deleteCause===''){
          this.$message.error("删除的理由不能为空！")
        }else {
          getAction(deleteUrl,"").then((res)=>{
            that.$message.success(res.message);
            this.add(this.reRecord);
          }).finally(() => {
            that.loading = false;
          });
        }

      },
    },
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>